package com.neutech.util;

import javax.imageio.ImageIO;
import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ImageUtil {
    public static final Map<String, Image> imageMap=new HashMap<>();
    static {

        imageMap.put("background",getImage("com/neutech/res/background.png"));
        imageMap.put("birds",getImage("com/neutech/res/birds.png"));
        imageMap.put("land",getImage("com/neutech/res/land.png"));
        imageMap.put("pie_down",getImage("com/neutech/res/pie_down.png"));
        imageMap.put("pie_up",getImage("com/neutech/res/pie_up.png"));
        imageMap.put("start_button",getImage("com/neutech/res/start_button.png"));

    }

    //将图片通过路径读取出来
    public static Image getImage(String path){
        Image image= null;
        try {
            image= ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return image;
    }

    //给私有图片设置get方法
    public static Image get(String key){
        return imageMap.get(key);
    }


}

